package com.hznu.jspFinal.controller;

import com.hznu.jspFinal.entity.QuestionType;
import com.hznu.jspFinal.myBeans.R;
import com.hznu.jspFinal.service.QuestionTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(description = "题目类型接口",value = "questiontype")
@RestController
@RequestMapping("/questionType")
public class QuestionTypeController {

    @Autowired
    private QuestionTypeService questionTypeService;

    @ApiOperation(value = "增加题目类型")
    @PostMapping("/addOne")
    public R addOne(@RequestBody QuestionType questionType){
        try{
            questionTypeService.insert(questionType);
            return R.ok();
        }catch (Exception e){
            e.printStackTrace();
            return R.error();
        }
    }

    @ApiOperation("删除该类型")
    @GetMapping("/remove/{id}")
    public R remove(@PathVariable Integer id){
        try{
            questionTypeService.delete(id);
            return R.ok();
        }catch (Exception e){
            e.printStackTrace();
            return R.error();
        }
    }

    @ApiOperation("查找")
    @GetMapping("/select/{id}")
    public R select(@PathVariable Integer id){
        try{
            return R.ok().put("data",questionTypeService.select(id));
        }catch (Exception e){
            e.printStackTrace();
            return R.error();
        }
    }

    @ApiOperation("返回所有的试题类型")
    @PostMapping("/selectAll")
    public R selectAll(){
        try{
            return R.ok().put("data",questionTypeService.selectAll());
        }catch (Exception e){
            e.printStackTrace();
            return R.error();
        }
    }

    @ApiOperation("修改试题")
    @PostMapping("/update")
    public R update(@RequestBody QuestionType questionType){
        try{
            questionTypeService.update(questionType);
            return R.ok();
        }catch (Exception e){
            e.printStackTrace();
            return R.error();
        }
    }



}
